<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/27
 * Time: 18:14
 */

namespace app\index\model;
use think\Model;
use think\Db;
class ConfigModel extends Model{
    // 确定链接表名
    protected $table = 'snake_config';
    public function getBanner($type=0){
        return Db::name('ad')->where(array('type'=>$type,'status'=>1))->order('list_order DESC ,id DESC ')->select();
    }
    public function getBook($type=0){
        return Db::name('post')->where(array('type'=>$type,'status'=>1))->order('addtime DESC ,id DESC ')->select();
    }
    public function getCompany(){
        return Db::name('articles')->where(array('id'=>1))->find();
    }
    public function getVip(){
        return Db::name('user_level')->order('id ASC')->select();
    }
    public function getCreditUrl(){
        return Db::name('config')->where(array('inc_type'=>'credit_url'))->value('value');
    }
    public function getService(){
        $ret=array(
            'tel'=>Db::name('config')->where(array('inc_type'=>'tel'))->value('value'),
            'wechat'=>'',
        );
        return $ret;
    }
    public function advice($param){
        $user_id=session('user_id');
        $map=array(
            'user_id'=>$user_id,
            'content'=>$param['content'],
            'contact'=>$param['contact'],
            'addtime'=>time()
        );
        try{
            $num=Db::name('feedback')->insert($map);
            if(false === $num){
                return msg(-1, '', '提交失败');
            }
            return msg(1,url('user/index'),'提交成功');
        }catch(\Exception $e){
            return msg(-1, '', $e->getMessage());
        }
    }
}